package zhang.automobileservice;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

public class AddCarActivity extends FarterActivity implements View.OnClickListener {
    private ImageView iv_addcar;
    private ImageView iv_cartype;
    private ImageView iv_carserious;
    private EditText et_carcodenum;
    private ImageView iv_carcode;
    private EditText tv_varcode;
    private TextView tv_cartype;
    private TextView tv_carserious;
    private EditText et_caralter;
    private Button bt_carbut;
    private String [] car ={"小型自动挡汽车","小型汽车","大型货车","大型客车","中型客车","城市公交车","牵引车"};
    private String [] location ={"京","津","冀","晋","蒙","辽","吉","黑","沪","苏","浙","皖","闽","赣","鲁","豫","鄂","湘","粤","桂","琼",
            "渝","川/蜀","贵/黔","云/滇","藏","陕","甘/陇","青","宁","新","港","澳","台"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_car);
        initView();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_addcar:
                finish();
                break;
            case R.id.tv_cartype:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setIcon(R.mipmap.icon).setTitle("请选择车辆型号");
                builder.setSingleChoiceItems(car, 1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        tv_cartype.setText(car[which]);
                        dialog.dismiss();
                    }
                }).show();
                break;
            case R.id.iv_cartype:
                View view = LayoutInflater.from(this).inflate(R.layout.pop_addcar_type, null);
                PopupWindow popWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
                popWindow.setBackgroundDrawable(new ColorDrawable(0xffffff));
                popWindow.setFocusable(true);
                popWindow.setOutsideTouchable(true);
                popWindow.setTouchable(true);
                setAlpha(0.6f);
                popWindow.showAtLocation(iv_cartype, Gravity.CENTER,0,0);
                popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        setAlpha(1);
                    }
                });
                break;
            case R.id.tv_carserious:
                break;
            case R.id.iv_carserious:
                break;
            case R.id.et_caralter:
                AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
                builder1.setIcon(R.mipmap.icon).setTitle("请选择车辆注册地");
                builder1.setSingleChoiceItems(location, 1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        et_caralter.setText(location[which]);
                        dialog.dismiss();
                    }
                }).show();
                break;
            case R.id.et_carcodenum:
                break;
            case R.id.iv_carcode:
                View view1 = LayoutInflater.from(this).inflate(R.layout.pop_recognise_carcode, null);
                PopupWindow popWindow1 = new PopupWindow(view1, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
                popWindow1.setBackgroundDrawable(new ColorDrawable(0xffffff));
                popWindow1.setFocusable(true);
                popWindow1.setOutsideTouchable(true);
                popWindow1.setTouchable(true);
                setAlpha(0.6f);
                popWindow1.showAtLocation(iv_cartype, Gravity.CENTER,0,0);
                popWindow1.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        setAlpha(1);
                    }
                });
                break;
            case R.id.tv_varcode:
                break;
            case R.id.bt_carbut:
                break;

        }
    }

    private void initView() {
        iv_cartype = (ImageView) findViewById(R.id.iv_cartype);
        iv_addcar = (ImageView) findViewById(R.id.iv_addcar);
        iv_cartype.setOnClickListener(this);
        iv_addcar.setOnClickListener(this);
        iv_carserious = (ImageView) findViewById(R.id.iv_carserious);
        iv_carserious.setOnClickListener(this);
        et_carcodenum = (EditText) findViewById(R.id.et_carcodenum);
        et_carcodenum.setOnClickListener(this);
        iv_carcode = (ImageView) findViewById(R.id.iv_carcode);
        iv_carcode.setOnClickListener(this);
        tv_varcode = (EditText) findViewById(R.id.tv_varcode);
        tv_varcode.setOnClickListener(this);
        tv_cartype = (TextView) findViewById(R.id.tv_cartype);
        tv_cartype.setOnClickListener(this);
        tv_carserious = (TextView) findViewById(R.id.tv_carserious);
        tv_carserious.setOnClickListener(this);
        et_caralter = (EditText) findViewById(R.id.et_caralter);
        et_caralter.setOnClickListener(this);
        bt_carbut = (Button) findViewById(R.id.bt_carbut);
        bt_carbut.setOnClickListener(this);
    }


    public void setAlpha(float alpha) {
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.alpha = alpha;
        window.setAttributes(params);
    }

}
